package students;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        // 5个学生成绩排序
        Student[] arr = new Student[3];
        for (int i = 0; i < arr.length; i++) {
            System.out.println("请输入第" + (i + 1) + "个人的名字：");
            String name = scan.next();
            System.out.println("请输入第" + (i + 1) + "个人的分数：");
            int score = scan.nextInt();

            Student obj = new Student(name, score); // 学生实例
            arr[i] = obj;
        }

//        for (int i = 0; i < arr.length; i++) {
//            System.out.println(arr[i].getName() + arr[i].getScore());
//        }

        for (int i = 0; i < arr.length; i++) {
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[i].getScore() > arr[j].getScore()) {
                    Student temp = new Student();
                    temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }

        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i].getName() + arr[i].getScore());
        }
    }
}
